#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/spi.h"
#include "hardware/i2c.h"
#include "hardware/dma.h"
#include "hardware/pio.h"
#include "hardware/interp.h"
#include "hardware/timer.h"
#include "hardware/watchdog.h"
#include "hardware/clocks.h"

#include "pico/mutex.h"
#include "pico/sem.h"
#include "FreeRTOS.h" /* Must come first. */
#include "task.h"     /* RTOS task related API prototypes. */
#include "queue.h"    /* RTOS queue related API prototypes. */
#include "timers.h"   /* Software timer related API prototypes. */
#include "semphr.h"   /* Semaphore related API prototypes. */


#include "lvgl.h"
#include "lv_demos.h"
#include "lv_examples.h"
#include "lv_port_disp.h"
#include "lv_port_indev.h"
#include "ui_app_clibrate_tp.h"

void task_led(void* pvParam)
{
    gpio_init(25);
    gpio_set_dir(25, true);
    gpio_put(25, true);

    for(;;)
    {
        vTaskDelay(200 / portTICK_PERIOD_MS);    // 延时1秒
        gpio_put(25, true);
        vTaskDelay(200 / portTICK_PERIOD_MS);    // 延时1秒
        gpio_put(25, false);
    }
}


void task_gui(void* pvParam)
{
    lv_init();
    lv_port_disp_init();
    lv_port_indev_init();

    // 校准参数
    // app_page_create(lv_scr_act());

    // lv_demo_benchmark();
    // lv_demo_music();
    // lv_demo_stress();

    // Example
    // lv_example_anim_1();
    lv_example_anim_2();

    while(1)
    {
        vTaskDelay(lv_task_handler());
    }
}



int main()
{
    stdio_init_all();

    // clock_configure(clk_sys,
    //                 CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLKSRC_CLK_SYS_AUX,
    //                 CLOCKS_CLK_SYS_CTRL_AUXSRC_VALUE_CLKSRC_PLL_SYS,
    //                 250 * MHZ,
    //                 250 * MHZ);

    printf("Hello, world!\n");
    printf("Sys clock:%d\n", clock_get_hz(clk_sys));

    TaskHandle_t task_led_hdl = NULL;
    xTaskCreate(task_led, "task_led", 128, NULL, 2, &task_led_hdl);

    TaskHandle_t task_gui_hdl = NULL;
    xTaskCreate(task_gui, "task_gui", 2048, NULL, 2, &task_gui_hdl);

    vTaskStartScheduler();

    return 0;
}
